﻿using CKS.Core.Framework;
using CKS.PLC.Action.Subscription.OP080;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZR.Model.Models.ProductionControl;

namespace CKS.PLC.Action.Subscription.OP80
{
    /// <summary>
    /// 动作编号202
    /// 右钎焊料架-查询工装-返回工装数据
    /// </summary>
    public class DB3011_Work202Action : OP80ActionBase
    {
        public DB3011_Work202Action(DecodeValue _value) : base(_value)
        {
        }
        public override void Execute()
        {
            var replayDB = 3010;
            var replayAction = 4;
            
            var replayPos = Value.GetPosition(replayDB, replayAction);
            var result = Value.Value.ToInt();
            var locationId = 2;//位置编号 1左 2右
            if (result == 1)
            {

                //查询数据库存储的工装位置写入到PLC

                var shelfId = Value.GetLinkData(102, 1).ToInt();
                QueryFixtureToPLC(replayDB, replayAction, replayPos, shelfId);

                EventBus.AddLog("OP80右-钎焊料架-查询料架工装数据");

            }
            else
            {
                AckWriteInt16(replayPos, 0);
                logger.LogInformation($"OP80右-钎焊料架-查询料架工装数据-信号重置");
            }
        }

        

    }
}
